/*
 * @Author: lll 1280388921@qq.com
 * @Date: 2025-05-07 00:19:26
 * @LastEditors: lll 1280388921@qq.com
 * @LastEditTime: 2025-05-07 00:19:27
 * @FilePath: /lesson38/lockGuard.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once

#include <pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t *lock)
        : lock_(lock)
    {
    }
    ~Mutex() {}
    void Lock()
    {
        pthread_mutex_lock(lock_);
    }
    void unLock()
    {
        pthread_mutex_unlock(lock_);
    }

private:
    pthread_mutex_t *lock_;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t *lock)
        : mutex(lock)
    {
        mutex.Lock();
    }
    ~LockGuard()
    {
        mutex.unLock();
    }

private:
    Mutex mutex;
};